package handler

import (
	"github.com/gin-gonic/gin"
	"net/http"
	"soul/api/request"
	"soul/inter/dao"
	"soul/inter/model"
)

func BarrageCreate(c *gin.Context) {
	var req request.BarrageCreate
	if err := c.ShouldBind(&req); err != nil {
		c.JSON(http.StatusOK, gin.H{
			"code": 10000,
			"msg":  "验证失败",
			"data": err.Error(),
		})
		return
	}
	var bar model.Barrages
	dao.GetOneByFields(&model.Barrages{}, &bar)
	bar = model.Barrages{
		UserId: req.UserId,
		Common: req.Common,
	}
	if !dao.Create(&bar) {
		c.JSON(http.StatusOK, gin.H{
			"code": 10000,
			"msg":  "弹幕发布失败",
			"data": nil,
		})
		return
	}
	c.JSON(http.StatusOK, gin.H{
		"code": http.StatusOK,
		"msg":  "ok",
		"data": bar,
	})
}
